﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KWIC
{
    /// <summary>
    /// A class to perform the circular shifts
    /// </summary>
    /// The following was created by mgsurya developed on the machineMGSURYA-PC on 12/4/2012, 9:32 AM
    public class CircularShift
    {
        /// <summary>
        /// Gets the CS.
        /// </summary>
        /// <param name="trimmedSentences">The trimmed sentences.</param>
        /// <returns></returns>
        /// The following was created by mgsurya developed on the machineMGSURYA-PC on 12/4/2012, 9:32 AM
        public List<string> getCS(List<string> trimmedSentences)
        {
            List<string> CS = new List<string>();
            Queue<String> q = new Queue<String>();

            startCSProcess(trimmedSentences, CS, q);

            return CS;
        }

        /// <summary>
        /// Starts the CS process.
        /// </summary>
        /// <param name="trimmedSentences">The trimmed sentences.</param>
        /// <param name="CS">The CS.</param>
        /// <param name="q">The q.</param>
        /// The following was created by mgsurya developed on the machineMGSURYA-PC on 12/4/2012, 9:32 AM
        private static void startCSProcess(List<string> trimmedSentences, List<string> CS, Queue<String> q)
        {
            for (int i = 0; i < trimmedSentences.Count(); i++)
            {
                foreach (string word in trimmedSentences[i].Split(default(char[])))
                {
                    q.Enqueue(word);
                }

                for (int j = 0; j < q.Count() - 1; j++)
                {
                    shiftOnce(CS, q);
                }
                q.Clear();
            }
        }

        /// <summary>
        /// Shifts the words in the queue once.
        /// </summary>
        /// <param name="CS">The CS.</param>
        /// <param name="q">The q.</param>
        /// The following was created by mgsurya developed on the machineMGSURYA-PC on 12/4/2012, 9:33 AM
        private static void shiftOnce(List<string> CS, Queue<String> q)
        {
            String firstWord = q.First();
            q.Dequeue();
            q.Enqueue(firstWord);

            CS.Add(String.Join(" ", q.ToArray()));
        }
    }
}